package demo1;

import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age &&
                Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
class NameComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
class Incmp implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
public class Test1 {
    public static void main(String[] args) {
        Student student = new Student("张三",12);
        Student student1 = new Student("张三",22);
        System.out.println(student == student1);
        System.out.println(student.equals(student1));
        System.out.println(student.compareTo(student1));
        NameComparator nameComparator = new NameComparator();
        int ret = nameComparator.compare(student,student1);
        System.out.println(ret);
        AgeComparator ageComparator = new AgeComparator();
        System.out.println(ageComparator.compare(student,student1));
        Incmp incmp = new Incmp();
        Queue<Integer> priorityQueue = new PriorityQueue<>(incmp);
        priorityQueue.offer(1);
        priorityQueue.offer(2);
        System.out.println(priorityQueue.poll());

        Queue<Integer> pri = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });
    }
}
